let express = require('express');
let router = express.Router();

const uploadExcelService = require('../service/uploadExcelService');

// 查询某个用户的所有上传文件
router.get('/getAllFiles', async (req, res, next) => {
    let result = await uploadExcelService.getAllFiles();
    res.status(result.success ? 200 : 400).json(result);
});

// 导入 第一个excel表格
router.post('/uploadExcel', async (req, res, next) => {
    // console.log(req.body);
    let { fileName, data } = req.body;
    let result = await uploadExcelService.uploadExcel(fileName, data);
    res.status(result.success ? 200 : 400).json(result);
});

// 下载表格
router.post('/downloadExcel', async (req, res, next) => {
    // console.log(req.body);
    let id = req.body.fileId;
    let result = await uploadExcelService.downloadExcel(id);
    res.status(result.success ? 200 : 400).json(result);
});

// 加载二级事项
router.post('/loadSubItem', async (req, res, next) => {
    let contentId = req.body.contentId;
    let result = await uploadExcelService.loadSubItem(contentId);
    res.status(result.success ? 200 : 400).json(result);
});

module.exports = router;





